package com.ssm.ssmcontroller;

import com.ssm.po.User;
import com.ssm.routerweb.DataSourceContextHolder;
import com.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mars-Hasee on 2017/8/6.
 */
@RestController
public class UserController4 {

    @Autowired
    private UserService userService;

    @RequestMapping("/ssm.action")
    public ModelAndView handleRequest() throws Exception {

        DataSourceContextHolder.setDbType("dataSource2");
        User user = userService.findone(1);
        System.out.println(user.getName());
        List<User> userList = new ArrayList<>();
        ModelAndView modelAndView = new ModelAndView();
        //相当于reuest 中的setAttrabute方法
        modelAndView.addObject("userList",userList);
        //指定视图
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
